/**
 *
 * Copyright Pact Lab of H.I.T.
 *
 * Designed and Implemented by Grid Researching Group, 
 * Pact Lab, Harbin
 * 
 * This Project is part of the national 973 Project:
 * Internet Based Virtual Computing Environment
 *
 * http://pact518.hit.edu.cn
 * 
 * Author:       Meteor <meteorlxk@gmail.com> 
 * Copyright:    pact518 
 * Version:      1.0
 * Created:      2009-4-21 
 * LastModified: 2009-4-21
 */
package edu.hit.pact.pgse.bean;

import java.io.Serializable;
import java.util.Date;

/**
 * @author Meteor
 *
 */
public class TaskPieceStatistics implements Serializable {

	private static final long serialVersionUID = -4974261540004712917L;
	
	private final long taskPieceId;
	private final String homePage;
	
	private long startTime;
	
	private long finishedTime;
	
	private int succeededPageNumber;
	
	private int failedPageNumber;
	
	private double averageDownloadSpeed;
	private double averageBacklinks;
	
	public TaskPieceStatistics(long taskPieceId, String homePage, long startTime, long finishedTime, 
			int succeededPageNumber, int failedPageNumber, double averageBacklinks) {
		this.taskPieceId = taskPieceId;
		this.homePage = homePage;
		this.startTime = startTime;
		this.finishedTime = finishedTime;
		
		this.succeededPageNumber = succeededPageNumber;
		this.failedPageNumber = failedPageNumber;
		
		if (startTime == finishedTime) {
			this.averageDownloadSpeed = 0.0;
		} else {
			this.averageDownloadSpeed = (double)succeededPageNumber * 1000/(finishedTime - startTime);
		}//end if
		this.averageBacklinks = averageBacklinks;
	}

	/**
	 * @return the taskPieceId
	 */
	public long getTaskPieceId() {
		return taskPieceId;
	}

	/**
	 * @return the startTime
	 */
	public long getStartTime() {
		return startTime;
	}

	public String getHomePage() {
		return homePage;
	}

	/**
	 * @return the finishedTime
	 */
	public long getFinishedTime() {
		return finishedTime;
	}

	/**
	 * @return the succeededPageNumber
	 */
	public int getSucceededPageNumber() {
		return succeededPageNumber;
	}

	/**
	 * @return the failedPageNumber
	 */
	public int getFailedPageNumber() {
		return failedPageNumber;
	}

	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}

	public void setFinishedTime(long finishedTime) {
		this.finishedTime = finishedTime;
	}

	public void setSucceededPageNumber(int succeededPageNumber) {
		this.succeededPageNumber = succeededPageNumber;
	}

	public void setFailedPageNumber(int failedPageNumber) {
		this.failedPageNumber = failedPageNumber;
	}

	public void setAverageDownloadSpeed(double averageDownloadSpeed) {
		this.averageDownloadSpeed = averageDownloadSpeed;
	}

	/**
	 * @return the averageDownloadSpeed
	 */
	public double getAverageDownloadSpeed() {
		return averageDownloadSpeed;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString(){
		StringBuffer content = new StringBuffer();
		content.append("\n--------------------------------------------\n");
		content.append("Time: " + new Date() + "\n");
		content.append("Task piece id : " + this.taskPieceId + "\n");
		content.append("HomePage : " + this.homePage + "\n");
		content.append("Start time :" + new Date(startTime) + "\n");
		content.append("FinishedTime time :" + new Date(finishedTime) + "\n");
		content.append("Succeeded page number: " + this.succeededPageNumber + "\n");
		content.append("Failed page number: " + this.failedPageNumber + "\n");
		content.append("Average download speed: " + this.averageDownloadSpeed + "\n");
		content.append("Average backlinks: " + this.averageBacklinks + "\n");
		content.append("--------------------------------------------\n");
		return content.toString();
	}
}
